import {http} from '@/utils/http'

interface ResponseType extends Promise<any> {
    data?: object;
    code?: number;
    message?: string;
}

/*
通过用户名获取用户id
*/
export const geUserIdByName = (params: object): ResponseType => http.request(
    'get',
    '/base/user/check/roles',
    {params},
)

/*
通过用户id获取角色管辖片区
*/
export const getAreayByUserId = (params: object): ResponseType => http.request(
    'get',
    '/tea-garden/field/user/list',
    {params},
)

/*
通过用户id获取角色管辖茶厂
*/
export const getFactoryByUserId = (params: object): ResponseType => http.request(
    'get',
    '/tea-garden/factory/user/list',
    {params},
)

/*
登录
*/
export const login = (data: object): ResponseType => http.request(
    'post',
    '/admin/login/token',
    {data},
)

export const getUserInfo = (): ResponseType => http.request(
    'get',
    '/admin/current/user',
)

// 单点登录获取token
export const getUserInfoByToken = (params: object) => http.request('get', '/auth/info', {params})

// 登录
export const getLogin = (data: object) => http.request('post', '/login', {data})

// 刷新token
export const refreshToken = (data: object) => http.request('post', '/refreshToken', {data})

export const getUserInfoPage = (data: object): ResponseType => http.request(
    'get',
    '/sys/user',
    {
        params: data
    }
)

export const addUser = (data: object): ResponseType => http.request(
    'post',
    '/sys/user',
    {
        data
    }
)

export const editUser = (data: object): ResponseType => http.request(
    'put',
    '/sys/user',
    {
        data
    }
)

export const removeUser = (params: object): ResponseType => http.request(
    'delete',
    '/sys/user',
    {
        params
    }
)
